home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / iw / progress.py < prev    next >
Encoding:
Python Source  |  2000-03-08  |  7.0 KB  |  197 lines

  1. from gtk import *
  2. from iw import *
  3. import string
  4. import rpm
  5. import time
  6. from threading import *
  7. from translate import _
  8.  
  9. class DoInstall (Thread):
  10.     def __init__ (self, icw, todo):
  11.         self.todo = todo
  12.         self.icw = icw
  13.         Thread.__init__ (self)
  14.  
  15.     def run (self):
  16.         rc = self.todo.doInstall ()
  17.         threads_enter ()
  18.         if rc:
  19.             self.icw.prevClicked ()
  20.         else:
  21.             self.icw.nextClicked ()
  22.         threads_leave ()
  23.                 
  24. class InstallProgressWindow (InstallWindow):
  25.  
  26.     def __init__ (self, ics):
  27.     InstallWindow.__init__ (self, ics)
  28.  
  29.         ics.setTitle (_("Installing Packages"))
  30.         ics.readHTML ("installing")
  31.         ics.setPrevEnabled (0)
  32.  
  33.         self.todo = ics.getToDo ()
  34.     self.numComplete = 0
  35.     self.sizeComplete = 0
  36.         
  37.     def setPackageScale (self, amount, total):
  38.         threads_enter ()
  39.     self.progress.update (float (amount) / total)
  40. #        self.totalProgress.update (float (self.sizeComplete + amount) / self.totalSize)
  41.         threads_leave ()
  42.  
  43.     def completePackage(self, header):
  44.         def formatTime(amt):
  45.             hours = amt / 60 / 60
  46.             amt = amt % (60 * 60)
  47.             min = amt / 60
  48.             amt = amt % 60
  49.             secs = amt
  50.  
  51.             return "%01d:%02d.%02d" % (int(hours) ,int(min), int(secs))
  52.  
  53.         threads_enter ()
  54.         self.numComplete = self.numComplete + 1
  55.         apply (self.clist.set_text, self.status["completed"]["packages"] + ("%d" % self.numComplete,))
  56.  
  57.     self.sizeComplete = self.sizeComplete + header[rpm.RPMTAG_SIZE]
  58.         apply (self.clist.set_text, self.status["completed"]["size"] +
  59.                                     ("%d M" % (self.sizeComplete / (1024 * 1024)),))
  60.  
  61.         apply (self.clist.set_text, self.status["remaining"]["packages"] +
  62.                                     ("%d" % (self.numTotal - self.numComplete),))
  63.  
  64.         apply (self.clist.set_text, self.status["remaining"]["size"] +
  65.                                     ("%d M" % ((self.totalSize - self.sizeComplete) / (1024 * 1024)),))
  66.  
  67.         # check to see if we've started yet
  68.         if (self.timeStarted == -1):
  69.             self.timeStarted = time.time ()
  70.             elapsedTime = 0
  71.         else:
  72.             elapsedTime = time.time() - self.timeStarted
  73.             
  74.         apply (self.clist.set_text, self.status["completed"]["time"] + ("%s" % formatTime(elapsedTime),))
  75.  
  76.     finishTime = (float (self.totalSize) / self.sizeComplete) * elapsedTime
  77.         apply (self.clist.set_text, self.status["total"]["time"] + ("%s" % formatTime(finishTime),))
  78.  
  79.     remainingTime = finishTime - elapsedTime
  80.         apply (self.clist.set_text, self.status["remaining"]["time"] + ("%s" % formatTime(remainingTime),))
  81.  
  82.         self.totalProgress.update (float (self.sizeComplete) / self.totalSize) 
  83.         threads_leave ()
  84.         
  85.         return
  86.     self.timeCompleteW.setText("%12s" % formatTime(elapsedTime))
  87.     self.timeTotalW.setText("%12s" % formatTime(finishTime))
  88.  
  89.     def setPackage(self, header):
  90.         threads_enter ()
  91.         self.curPackage["package"].set_text ("%s-%s-%s" % (header[rpm.RPMTAG_NAME],
  92.                                                            header[rpm.RPMTAG_VERSION],
  93.                                                            header[rpm.RPMTAG_RELEASE]))
  94.         size = str (header[rpm.RPMTAG_SIZE] / 1024)
  95.         if len (size) > 3:
  96.             size = size [0:len(size) - 3] + ',' + size[len(size) - 3:]
  97.         self.curPackage["size"].set_text ("%s KBytes" % size)
  98.         summary = header[rpm.RPMTAG_SUMMARY]
  99.     if (summary == None):
  100.             summary = "(none)"
  101.         self.curPackage["summary"].set_text (summary)
  102.         threads_leave ()
  103.  
  104.     def setSizes (self, total, totalSize):
  105.         threads_enter ()
  106.         self.numTotal = total
  107.         self.totalSize = totalSize
  108.         self.timeStarted = -1
  109.  
  110.         apply (self.clist.set_text, self.status["total"]["packages"] + ("%d" % total,))
  111.         
  112.         apply (self.clist.set_text, self.status["total"]["size"] +
  113.                                     ("%d M" % (totalSize / (1024 * 1024)),))
  114.         threads_leave ()
  115.  
  116.     def allocate (self, widget, *args):
  117.         if self.frobnicatingClist: return
  118.         
  119.         self.frobnicatingClist = 1
  120.         width = widget.get_allocation ()[2] - 50
  121.         for x in range (4):
  122.             widget.set_column_width (x, width / 4)
  123.  
  124.             
  125.     def getScreen (self):
  126.     table = GtkTable (3, 2)
  127.         self.curPackage = { "package" : _("Package"),
  128.                             "size"    : _("Size"),
  129.                             "summary" : _("Summary") }
  130.         i = 0
  131.         for key in ("package", "size", "summary"):
  132.             label = GtkLabel ("%s: " % (self.curPackage[key],))
  133.             label.set_alignment (0, 0)
  134.             table.attach (label, 0, 1, i, i+1, FILL, FILL)
  135.             label = GtkLabel ()
  136.             label.set_alignment (0, 0)
  137.             label.set_line_wrap (TRUE)
  138.             if key == "summary":
  139.                 label.set_text ("\n\n")
  140.             self.curPackage[key] = label
  141.             table.attach (label, 1, 2, i, i+1, FILL, FILL)
  142.             i = i + 1
  143.  
  144.         vbox = GtkVBox (FALSE, 10)
  145.         vbox.pack_start (table, FALSE)
  146.  
  147.     self.progress = GtkProgressBar ()
  148.         self.totalProgress = GtkProgressBar ()
  149.         vbox.pack_start (self.progress, FALSE)
  150.  
  151.         self.status =  {
  152.             "total" :     { "packages" : (0, 1),
  153.                             "size"     : (0, 2),
  154.                             "time"     : (0, 3) },
  155.             "completed" : { "packages" : (1, 1),
  156.                             "size"     : (1, 2),
  157.                             "time"     : (1, 3) },
  158.             "remaining" : { "packages" : (2, 1),
  159.                             "size"     : (2, 2),
  160.                             "time"     : (2, 3) }
  161.             }
  162.  
  163.         clist = GtkCList (4, (_("Status"), _("Packages"), _("Size"), _("Time")))
  164.         clist.set_column_justification (0, JUSTIFY_LEFT)
  165.         clist.set_column_justification (1, JUSTIFY_RIGHT)
  166.         clist.set_column_justification (2, JUSTIFY_RIGHT)
  167.         clist.set_column_justification (3, JUSTIFY_RIGHT)
  168.         clist.append ((_("Total"),     "0", "0 M", "0:00.00"))
  169.         clist.append ((_("Completed"), "0", "0 M", "0:00.00"))
  170.         clist.append ((_("Remaining"), "0", "0 M", "0:00.00"))
  171.         self.frobnicatingClist = 0
  172.         
  173.     clist.connect_after ("size_allocate", self.allocate)
  174.         for x in range (4):
  175.             clist.column_title_passive (x)
  176.         for x in range (3):
  177.             clist.set_selectable (x, FALSE)
  178.         clist['can_focus'] = FALSE
  179.         self.clist = clist
  180. #        align = GtkAlignment (0.5, 0.5)
  181. #        align.add (clist)
  182. #        vbox.pack_start (align, FALSE)
  183.         hbox = GtkHBox (FALSE, 5)
  184.         hbox.pack_start (clist, TRUE)
  185.         vbox.pack_start (hbox, FALSE)
  186.         vbox.pack_start (self.totalProgress, FALSE)
  187.  
  188.     self.ics.getInstallInterface ().setPackageProgressWindow (self)
  189.         ii = self.ics.getInstallInterface ()
  190.         icw = ii.icw
  191.         worker = DoInstall (icw, self.todo)
  192.         worker.start ()
  193.  
  194.     vbox.set_border_width (5)
  195.     return vbox
  196.  
  197.